<?php
/**
* TopSites - Компонент каталога ссылок для Joostina CMS.
* @author:      Лаборатория сайтов, http://sitelab.net.ru
* @version:     1.9
* @release:     2010.02.07
* @package:     com_topsites
* @copyright:   (C) 2010 http://sitelab.net.ru,  see /administrator/components/com_topsites/copyright.php
* @license:     http://www.gnu.org/copyleft/gpl.html GNU/GPL
**/

defined( '_VALID_MOS' ) or die( '' );

class MAIL_topsites
{

	// Добавление новой ссылки: письмо пользователю.
	function AddLink_MailForUser_TL ( $row ) {
		$database = &database::getInstance();
		global $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_sitename, $my, $tl_email_default, $tl_to_demand_link_back;
		
		//Запроосы к БД перед отправкой писем
		$database->setQuery( "SELECT email FROM #__users WHERE id=".$my->id);
		$row->email=$database->loadResult();
				  
		$database->setQuery( "SELECT name FROM #__topsites_categories WHERE id=".$row->catid);
		$row->catname=$database->loadResult();
				  
		// Письмо
		$subject = $mosConfig_sitename." - "._TL_LINK_IS_ADD;
		$text = "\r\n"._TL_HELLO;
		$text.= "\r\n\r\n"._TL_YOU_LINK_ADD.$mosConfig_sitename;
		$text.= "\r\n\r\n"._TL_LINK_BE_CHECKED;
		$text.= "\r\n\r\n"._TL_YOU_LINK;
		$text.= "\r\n"."______________________________";
		$text.= "\r\n\r\n"._TL_CATEGORY.': '.$row->catname;
		$text.= "\r\n\r\n"._TL_LINK.': '.$row->name;
		$text.= "\r\n\r\n"._TL_DESCRIPTION_LINK.': '.$row->description;
		$text.= "\r\n\r\n"._TL_URL_LINK.': '.$row->url;
		if ( $tl_to_demand_link_back ) $text.= "\r\n\r\n"._TL_URL_BACK_LINK.': '.$row->url_back;
		$text.= "\r\n\r\n"."______________________________";
		$text.= "\r\n\r\n"._TL_WE_THANK_YOU.$mosConfig_sitename;
		$text.= "\r\n\r\n"."______________________________";
		   
		mosMail( $mosConfig_mailfrom,$mosConfig_fromname,$row->email,$subject,$text);
	}
	
	// Добавление новой ссылки: письмо администратору.
	function AddLink_MailForAdmin_TL ( $row ) {
		$database = &database::getInstance();
		global $Itemid, $tl_email_default, $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_sitename, $tl_to_demand_link_back;
		
		//Запроосы к БД перед отправкой писем
		$database->setQuery( "SELECT name FROM #__topsites_categories WHERE id=".$row->catid);
		$row->catname=$database->loadResult();
		
		// Письмо
		$row->email= $tl_email_default;
						  
		$subject = $mosConfig_sitename." - "._TL_LINK_IS_ADD;
		$text = "\r\n"._TL_LINK_BEEN_ADD;
		$text.= "\r\n\r\n"."______________________________";
		$text.= "\r\n\r\n"._TL_CATEGORY.': '.$row->catname;
		$text.= "\r\n\r\n"._TL_LINK.': '.$row->name;
		$text.= "\r\n\r\n"._TL_DESCRIPTION_LINK.': '.$row->description;
		$text.= "\r\n\r\n"._TL_URL_LINK.': '.$row->url;
		if ( $tl_to_demand_link_back ) $text.= "\r\n\r\n"._TL_URL_BACK_LINK.': '.$row->url_back;
		$text.= "\r\n\r\n"."______________________________";
		$text.= "\r\n\r\n"._TL_LINK_FOR_APPROVED.': '.JPATH_SITE.'/index.php?option=com_topsites&Itemid='.$Itemid.'&task=publishmail&linkid='.$row->id.'&controlofid='.$row->controlofid;
		$text.= "\r\n\r\n"._TL_LINK_FOR_REFUSAL_APPROVED.': '.JPATH_SITE.'/index.php?option=com_topsites&Itemid='.$Itemid.'&task=refusal&linkid='.$row->id.'&controlofid='.$row->controlofid;
		$text.= "\r\n\r\n"."______________________________";
		   
		mosMail( $mosConfig_mailfrom,$mosConfig_fromname,$row->email,$subject,$text);
	}

// Редактирование ссылки: письмо пользователю.
	function EditLink_MailForUser_TL ( $row ) {
		$database = &database::getInstance();
		global $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_sitename, $my, $tl_email_default, $tl_to_demand_link_back;
		
		//Запроосы к БД перед отправкой писем
		$database->setQuery( "SELECT email FROM #__users WHERE id=".$my->id);
		$row->email=$database->loadResult();
			  
		$database->setQuery( "SELECT name FROM #__topsites_categories WHERE id=".$row->catid);
		$row->catname=$database->loadResult();
			  
		// Письмо
		$subject = $mosConfig_sitename." - "._TL_LINK_EDIT;
		$text = "\r\n"._TL_HELLO;
		$text.= "\r\n\r\n"._TL_YOU_LINK_EDIT.$mosConfig_sitename;
		$text.= "\r\n\r\n"._TL_LINK_BE_CHECKED;
		$text.= "\r\n\r\n"._TL_YOU_LINK;
		$text.= "\r\n"."______________________________";
		$text.= "\r\n\r\n"._TL_CATEGORY.': '.$row->catname;
		$text.= "\r\n\r\n"._TL_LINK.': '.$row->name;
		$text.= "\r\n\r\n"._TL_DESCRIPTION_LINK.': '.$row->description;
		$text.= "\r\n\r\n"._TL_URL_LINK.': '.$row->url;
		if ( $tl_to_demand_link_back ) $text.= "\r\n\r\n"._TL_URL_BACK_LINK.': '.$row->url_back;
		$text.= "\r\n\r\n"."______________________________";
		$text.= "\r\n\r\n"._TL_WE_THANK_YOU.$mosConfig_sitename;
		$text.= "\r\n\r\n"."______________________________";
		   
		mosMail( $mosConfig_mailfrom,$mosConfig_fromname,$row->email,$subject,$text);
	}
		
	// Редактирование ссылки: письмо администратору.
	function EditLink_MailForAdmin_TL ( $row ) {
	
		global $Itemid, $tl_email_default, $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_sitename, $tl_to_demand_link_back;
		
		// Письмо
		$row->email= $tl_email_default;
							  
		$subject = $mosConfig_sitename." - "._TL_LINK_EDIT;
		$text = "\r\n"._TL_LINK_BEEN_EDIT;
		$text.= "\r\n\r\n"."______________________________";
		$text.= "\r\n\r\n"._TL_CATEGORY.': '.$row->catname;  
		$text.= "\r\n\r\n"._TL_LINK.': '.$row->name;
		$text.= "\r\n\r\n"._TL_DESCRIPTION_LINK.': '.$row->description;
		$text.= "\r\n\r\n"._TL_URL_LINK.': '.$row->url;
		if ( $tl_to_demand_link_back ) $text.= "\r\n\r\n"._TL_URL_BACK_LINK.': '.$row->url_back;
		$text.= "\r\n\r\n"."______________________________";
		$text.= "\r\n\r\n"._TL_LINK_FOR_APPROVED.': '.JPATH_SITE.'/index.php?option=com_topsites&Itemid='.$Itemid.'&task=publishmail&linkid='.$row->id.'&controlofid='.$row->controlofid;
		$text.= "\r\n\r\n"._TL_LINK_FOR_REFUSAL_APPROVED.': '.JPATH_SITE.'/index.php?option=com_topsites&Itemid='.$Itemid.'&task=refusal&linkid='.$row->id.'&controlofid='.$row->controlofid;
		$text.= "\r\n\r\n"."______________________________";
			   
		mosMail( $mosConfig_mailfrom,$mosConfig_fromname,$row->email,$subject,$text);
	}

}